package com.auth.manage.notice.facade;

import com.auth.manage.base.responce.BaseResponce;
import com.auth.manage.common.notice.api.request.SendCaptchaRequest;
import com.auth.manage.common.notice.api.service.NoticeFacadeService;
import com.auth.manage.limiter.SlidingWindowRateLimiter;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.data.redis.core.StringRedisTemplate;


@DubboService(version = "1.0.0")
@RequiredArgsConstructor
public class NoticeFacadeServiceImpl implements NoticeFacadeService {
    private final SlidingWindowRateLimiter rateLimiter;
    private StringRedisTemplate redisTemplate;


    @Override
    public BaseResponce sendCaptcha(SendCaptchaRequest request) {
        // 1.滑动窗口限流
        Boolean access = rateLimiter.tryAcquire(request.getTelephone(), 1, 60);  // 对于telephone这个key，60秒内只能接收一次
        // 2.todo 调用第三方api发送验证码
        // 3.返回结果
        return BaseResponce.success();
    }
}
